package com.loie.xcx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.loie.xcx.mapper.BuyerCodeApplyMapper;
import com.loie.xcx.model.zxb.BuyerCodeApply;
import com.loie.xcx.service.BuyerCodeApplyService;
import com.loie.xcx.util.CopyClass;
import com.sinosure.edi.polo.BuyerCodeApplyInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author testjava
 * @since 2023-03-24
 */
@Slf4j
@Service

public class BuyerCodeApplyServiceImpl extends ServiceImpl<BuyerCodeApplyMapper, BuyerCodeApply> implements BuyerCodeApplyService {

    @Autowired
    private BuyerCodeApplyMapper buyerCodeApplyMapper;

    @Override
    public
    List<BuyerCodeApplyInfo> getBuyerCodeApplylist(String recordid) {

        QueryWrapper<BuyerCodeApply> wrapper = new QueryWrapper<>();
//        String recordid = "4E56FBF4-F0B9-422E-A129-C0FB130B184B";
//        String modulename = "赊销额度申请";
        wrapper.select(" * ");
        if (StringUtils.isNotBlank(recordid))
            wrapper.eq("RecordID", recordid);
        wrapper.eq("state", "待审批");
        List<BuyerCodeApply> buyerCodeApplyList = buyerCodeApplyMapper.selectList(wrapper);
        List<BuyerCodeApplyInfo> buyerCodeApplyInfoList = new ArrayList<BuyerCodeApplyInfo>();
        for (BuyerCodeApply buyerCodeApply : buyerCodeApplyList) {
            BuyerCodeApplyInfo buyerCodeApplyInfo = new BuyerCodeApplyInfo();
            String sourcestr = "corpSerialNo,clientNo,shtName,engName,chnName,engAddress,countryCode";
            String deststr = "corpserialno,businesscorpno,shortname,engname,chnname,buyeraddr,countrycode";
            String[] sourcearr = sourcestr.split(",");
            String[] destarr = deststr.split(",");
            try {
                CopyClass.copyFieldsStr(buyerCodeApply, buyerCodeApplyInfo, sourcearr, destarr);
                log.info("买方代码/买方英文名称:" + buyerCodeApply.getEngName() + "提交");

                System.out.println();
            } catch (Exception e) {
                e.printStackTrace();
            }
            //buyerCodeApplyInfo.setBusinesscorpno();
            buyerCodeApplyInfo.setIfgov("0");
            buyerCodeApplyInfo.setIfquotedcompany("0");
            buyerCodeApplyInfoList.add(buyerCodeApplyInfo);
        }

        return buyerCodeApplyInfoList;
    }


}
